package cn.tedu.bonfire.front.content.controller;

import cn.tedu.bonfire.common.pojo.po.ArticleSearchPO;
import cn.tedu.bonfire.common.pojo.vo.PageData;
import cn.tedu.bonfire.common.web.JsonResult;
import cn.tedu.bonfire.front.content.service.IArticleSearchService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/search")
@Api(tags = "7. 搜索模块")
public class ArticleSearchController {
    @Autowired
    private IArticleSearchService articleSearchService;

    @GetMapping("/article/{keyword}")
    @ApiOperation("搜索文章")
    @ApiOperationSupport(order = 500)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键词", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult articleSearch(@PathVariable String keyword, Integer pageNum) {
        Integer page = pageNum == null ? 1 : pageNum;
        PageData<ArticleSearchPO> pageData = articleSearchService.search(keyword, page);
        return JsonResult.ok(pageData);
    }
}
